package net.huashitong.ssydt;

import java.io.Serializable;
import java.util.List;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2018.01.15
 */
public class PaginationResult<T extends Serializable> implements Serializable {

    private static final long serialVersionUID = -5159532271019977681L;

    /**
     * 读取记录数
     */
    private int pageSize;
    /**
     * 当前页
     */
    private int pageNumber;
    /**
     * 总页数
     */
    private int pageCount;
    /**
     * 总记录数
     */
    private int pageRecords;
    /**
     * 数据列表
     */
    private List<T> list;

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        calcPageCount();
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getPageRecords() {
        return pageRecords;
    }

    public void setPageRecords(int pageRecords) {
        this.pageRecords = pageRecords;
        calcPageCount();
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    private void calcPageCount() {
        if (pageSize > 0 && pageRecords > 0) {
            this.pageCount = (pageRecords + pageSize - 1) / pageSize;
        }
    }

    @Override
    public String toString() {
        return "PaginationResult{" +
                "pageSize=" + pageSize +
                ", pageNumber=" + pageNumber +
                ", pageCount=" + pageCount +
                ", pageRecords=" + pageRecords +
                ", list=" + list +
                '}';
    }
}

